package com.briup.srms.base.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.srms.base.bean.DictData;
import com.briup.srms.base.dao.DictDataMapper;
import com.briup.srms.base.dao.extend.DictDataExtendMapper;
import com.briup.srms.base.service.IDictDataService;
import com.jacky.base.utils.CustomerException;
import com.jacky.base.utils.PageVM;

@Service
public class DictDataServiceImpl implements IDictDataService {

	@Autowired
	private DictDataMapper dictDataMapper;
	@Autowired
	private DictDataExtendMapper dictDataExtendMapper;

	@Override
	public PageVM<DictData> pageQuery(int page, int pageSize) {
		List<DictData> list = dictDataExtendMapper.query(page, pageSize);
		long total = dictDataExtendMapper.count();
		return new PageVM<>(page, pageSize, total, list);
	}

	@Override
	public void saveOrUpdate(DictData dictData) {
		if(dictData.getId() == null) {
			dictDataMapper.insert(dictData);
		} else {
			dictDataMapper.updateByPrimaryKey(dictData);
		}
	}

	@Override
	public void deleteById(long id) {
		DictData dict = dictDataMapper.selectByPrimaryKey(id);
		if(dict == null) {
			throw new CustomerException("要删除的数据不存在");
		}
		dictDataMapper.deleteByPrimaryKey(id);
	}

}
